package com.hdaccp.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.hdaccp.dao.CommonDao;
import com.hdaccp.dao.ZongDao;
import com.hdaccp.dao.impl.ZongDaoimpl;
import com.hdaccp.entity.Zong;

@WebServlet(urlPatterns="/san.do")
public class sanservlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int mm=Integer.parseInt(request.getParameter("mm"));
		if(mm==1){
				yi(request,response);		
		}else if(mm==2){
			er(request,response);
		}else if(mm==3){
			san(request,response);
		}
		
	}
	public void yi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int id=Integer.parseInt(request.getParameter("id"));
		String tt=request.getParameter("tt");
		ZongDao zz=new ZongDaoimpl();
		boolean f=zz.getUproblem(tt, id);
		if(f){
			riqi r = new riqi();
			r.update(request, response,id);
			CommonDao cd = new ZongDaoimpl();
			List<Zong> list = cd.getAll();
			Gson gson = new Gson();
			PrintWriter out = response.getWriter();
			out.print(gson.toJson(list));
			out.close();
		}
		
		
	}
	public void er(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int id=Integer.parseInt(request.getParameter("id"));
		String tt=request.getParameter("tt");
		ZongDao zz=new ZongDaoimpl();
		boolean f=zz.getUMater(tt, id);
		if(f){
			riqi r = new riqi();
			r.update(request, response,id);
			CommonDao cd = new ZongDaoimpl();
			List<Zong> list = cd.getAll();
			Gson gson = new Gson();
			PrintWriter out = response.getWriter();
			out.print(gson.toJson(list));
			out.close();
		}
		
		
	}
	public void san(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int id=Integer.parseInt(request.getParameter("id"));
		String tt=request.getParameter("tt");
		ZongDao zz=new ZongDaoimpl();
		boolean f=zz.getUremark(tt, id);
		if(f){
			riqi r = new riqi();
			r.update(request, response,id);
			CommonDao cd = new ZongDaoimpl();
			List<Zong> list = cd.getAll();
			Gson gson = new Gson();
			PrintWriter out = response.getWriter();
			out.print(gson.toJson(list));
			out.close();
		}
		
		
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html");
		doGet(request,response);
	}

}
